﻿namespace AnyOffice.DAL
{
    using AnyOffice.Model;
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class FlowProcessDao
    {
        public DataSet AutoUser(SqlConnection conn, int runId, int prcsId)
        {
            string commandText = "SELECT [UserId],[UserName] FROM [dbo].[Flow_Process], [dbo].[Flow_Run], [dbo].[Users] WHERE [Flow_Process].[FlowId] = [Flow_Run].[FlowId] AND [Flow_Process].[PrcsId] = @PrcsId AND [Flow_Run].[RunId] = @RunId AND [Flow_Process].[AutoUserOp] = [Users].[UserId] ORDER BY [Users].[UserNo] ASC ";
            commandText = commandText + "SELECT [UserId],[UserName] FROM [dbo].[Flow_Process], [dbo].[Flow_Run], [dbo].[Users] WHERE [Flow_Process].[FlowId] = [Flow_Run].[FlowId] AND [Flow_Process].[PrcsId] = @PrcsId AND [Flow_Run].[RunId] = @RunId AND CHARINDEX(',' + [Users].[UserId] + ',',',' + ISNULL(CAST([Flow_Process].[AutoUser] AS nvarchar(2000)) ,'') + ',') > 0 ORDER BY [Users].[UserNo] ASC";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@RunId", SqlDbType.Int);
            commandParameters[0].Value = runId;
            commandParameters[1] = new SqlParameter("@PrcsId", SqlDbType.Int);
            commandParameters[1].Value = prcsId;
            return SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
        }

        public DataTable ByDept(SqlConnection conn, int id)
        {
            string commandText = "DECLARE @PrcsUser nvarchar(4000) DECLARE @PrcsDept nvarchar(2000) DECLARE @PrcsPriv nvarchar(2000) SELECT @PrcsUser = CAST([PrcsUser] AS nvarchar(4000)), @PrcsDept = CAST([PrcsDept] AS nvarchar(2000)), @PrcsPriv = CAST([PrcsPriv] AS nvarchar(2000)) FROM [dbo].[Flow_Process] WHERE [Flow_Process].[Id] = @Id SELECT [DeptId], [ParentDept], [DeptName] FROM [dbo].[Department] WHERE ((@PrcsDept = 'ALL_DEPT' OR CHARINDEX(',' + CAST([DeptId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsDept,'') + ',') > 0) OR [DeptId] IN ( SELECT DISTINCT [DeptId] FROM [dbo].[Users] WHERE (CHARINDEX(',' + [UserId] + ',',',' + ISNULL(@PrcsUser,'') + ',') > 0) OR (CHARINDEX(',' + CAST([PrivId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsPriv,'') + ',') > 0) ) ) AND [DeptId] <> -1 ORDER BY [DeptNo] ASC";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int) };
            commandParameters[0].Value = id;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Users";
            return set.Tables[0];
        }

        public DataTable ByPriv(SqlConnection conn, int id)
        {
            string commandText = "DECLARE @PrcsUser nvarchar(4000) DECLARE @PrcsDept nvarchar(2000) DECLARE @PrcsPriv nvarchar(2000) SELECT @PrcsUser = CAST([PrcsUser] AS nvarchar(4000)), @PrcsDept = CAST([PrcsDept] AS nvarchar(2000)), @PrcsPriv = CAST([PrcsPriv] AS nvarchar(2000)) FROM [dbo].[Flow_Process] WHERE [Flow_Process].[Id] = @Id SELECT [PrivId], [PrivName] FROM [dbo].[User_Priv] WHERE (CHARINDEX(',' + CAST([PrivId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsPriv,'') + ',') > 0) OR [PrivId] IN ( SELECT DISTINCT [PrivId] FROM [dbo].[Users] WHERE ( @PrcsDept = 'ALL_DEPT' OR (CHARINDEX(',' + [UserId] + ',',',' + ISNULL(@PrcsUser,'') + ',') > 0) OR (CHARINDEX(',' + CAST([DeptId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsDept,'') + ',') > 0) ) AND [DeptId] <> -1 ) ORDER BY [PrivNo] ASC";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int) };
            commandParameters[0].Value = id;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Users";
            return set.Tables[0];
        }

        public DataTable ByUser(SqlConnection conn, int id)
        {
            string commandText = "DECLARE @PrcsUser nvarchar(4000) DECLARE @PrcsDept nvarchar(2000) DECLARE @PrcsPriv nvarchar(2000) SELECT @PrcsUser = CAST([PrcsUser] AS nvarchar(4000)), @PrcsDept = CAST([PrcsDept] AS nvarchar(2000)), @PrcsPriv = CAST([PrcsPriv] AS nvarchar(2000)) FROM [dbo].[Flow_Process] WHERE [Flow_Process].[Id] = @Id SELECT [Users].[UserId], [Users].[UserName], [Users].[DeptId], [Department].[DeptName], [Users].[PrivId], [User_Priv].[PrivName] FROM [dbo].[Users], [dbo].[Department], [dbo].[User_Priv] WHERE ( @PrcsDept = 'ALL_DEPT' OR (CHARINDEX(',' + [Users].[UserId] + ',',',' + ISNULL(@PrcsUser,'') + ',') > 0) OR (CHARINDEX(',' + CAST([Users].[DeptId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsDept,'') + ',') > 0) OR (CHARINDEX(',' + CAST([Users].[PrivId] AS nvarchar(20)) + ',',',' + ISNULL(@PrcsPriv,'') + ',') > 0) ) AND [Users].[DeptId] <> -1 AND [Users].[DeptId] = [Department].[DeptId] AND [Users].[PrivId] = [User_Priv].[PrivId] ORDER BY [User_Priv].[PrivNo] ASC, [Department].[DeptNo] ASC, [Users].[UserNo] ASC";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int) };
            commandParameters[0].Value = id;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Users";
            return set.Tables[0];
        }

        public void Delete(SqlConnection conn, int Ol)
        {
            string commandText = "DELETE FROM [dbo].[Flow_Process] WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int) };
            commandParameters[0].Value = Ol;
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public int Insert(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "INSERT INTO [dbo].[Flow_Process] ( [FlowId], [PrcsId], [PrcsName], [PrcsItem], [HiddenItem], [PrcsUser], [PrcsDept], [PrcsPriv], [PrcsTo], [SetLeft], [SetTop], [Plugin], [AutoItem], [PrcsIn], [PrcsOut], [PrcsInSet], [PrcsOutSet], [AttachmentFlag], [Feedback], [SignLook], [TurnPriv], [MailTo], [UserFilter], [AutoType], [UserLock], [TopDefault], [AutoUserOp], [AutoUser], [TimeOut] ) VALUES ( @FlowId, @PrcsId, @PrcsName, @PrcsItem, @HiddenItem, @PrcsUser, @PrcsDept, @PrcsPriv, @PrcsTo, @SetLeft, @SetTop, @Plugin, @AutoItem, @PrcsIn, @PrcsOut, @PrcsInSet, @PrcsOutSet, @AttachmentFlag, @Feedback, @SignLook, @TurnPriv, @MailTo, @UserFilter, @AutoType, @UserLock, @TopDefault, @AutoUserOp, @AutoUser, @TimeOut ) SELECT SCOPE_IDENTITY() AS RetValue";
            SqlParameter[] commandParameters = new SqlParameter[0x1d];
            commandParameters[0] = new SqlParameter("@FlowId", SqlDbType.Int);
            commandParameters[0].Value = data.FlowId;
            commandParameters[1] = new SqlParameter("@PrcsId", SqlDbType.Int);
            commandParameters[1].Value = data.PrcsId;
            commandParameters[2] = new SqlParameter("@PrcsName", SqlDbType.NVarChar, 200);
            commandParameters[2].Value = data.PrcsName;
            commandParameters[3] = new SqlParameter("@PrcsItem", SqlDbType.NText);
            if (data.PrcsItemIsNull)
            {
                commandParameters[3].Value = DBNull.Value;
            }
            else
            {
                commandParameters[3].Value = data.PrcsItem;
            }
            commandParameters[4] = new SqlParameter("@HiddenItem", SqlDbType.NText);
            if (data.HiddenItemIsNull)
            {
                commandParameters[4].Value = DBNull.Value;
            }
            else
            {
                commandParameters[4].Value = data.HiddenItem;
            }
            commandParameters[5] = new SqlParameter("@PrcsUser", SqlDbType.NText);
            if (data.PrcsUserIsNull)
            {
                commandParameters[5].Value = DBNull.Value;
            }
            else
            {
                commandParameters[5].Value = data.PrcsUser;
            }
            commandParameters[6] = new SqlParameter("@PrcsDept", SqlDbType.NText);
            if (data.PrcsDeptIsNull)
            {
                commandParameters[6].Value = DBNull.Value;
            }
            else
            {
                commandParameters[6].Value = data.PrcsDept;
            }
            commandParameters[7] = new SqlParameter("@PrcsPriv", SqlDbType.NText);
            if (data.PrcsPrivIsNull)
            {
                commandParameters[7].Value = DBNull.Value;
            }
            else
            {
                commandParameters[7].Value = data.PrcsPriv;
            }
            commandParameters[8] = new SqlParameter("@PrcsTo", SqlDbType.NText);
            if (data.PrcsToIsNull)
            {
                commandParameters[8].Value = DBNull.Value;
            }
            else
            {
                commandParameters[8].Value = data.PrcsTo;
            }
            commandParameters[9] = new SqlParameter("@SetLeft", SqlDbType.Int);
            commandParameters[9].Value = data.SetLeft;
            commandParameters[10] = new SqlParameter("@SetTop", SqlDbType.Int);
            commandParameters[10].Value = data.SetTop;
            commandParameters[11] = new SqlParameter("@Plugin", SqlDbType.NText);
            if (data.PluginIsNull)
            {
                commandParameters[11].Value = DBNull.Value;
            }
            else
            {
                commandParameters[11].Value = data.Plugin;
            }
            commandParameters[12] = new SqlParameter("@AutoItem", SqlDbType.NText);
            if (data.AutoItemIsNull)
            {
                commandParameters[12].Value = DBNull.Value;
            }
            else
            {
                commandParameters[12].Value = data.AutoItem;
            }
            commandParameters[13] = new SqlParameter("@PrcsIn", SqlDbType.NText);
            if (data.PrcsInIsNull)
            {
                commandParameters[13].Value = DBNull.Value;
            }
            else
            {
                commandParameters[13].Value = data.PrcsIn;
            }
            commandParameters[14] = new SqlParameter("@PrcsOut", SqlDbType.NText);
            if (data.PrcsOutIsNull)
            {
                commandParameters[14].Value = DBNull.Value;
            }
            else
            {
                commandParameters[14].Value = data.PrcsOut;
            }
            commandParameters[15] = new SqlParameter("@PrcsInSet", SqlDbType.NText);
            if (data.PrcsInSetIsNull)
            {
                commandParameters[15].Value = DBNull.Value;
            }
            else
            {
                commandParameters[15].Value = data.PrcsInSet;
            }
            commandParameters[0x10] = new SqlParameter("@PrcsOutSet", SqlDbType.NText);
            if (data.PrcsOutSetIsNull)
            {
                commandParameters[0x10].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x10].Value = data.PrcsOutSet;
            }
            commandParameters[0x11] = new SqlParameter("@AttachmentFlag", SqlDbType.Int);
            commandParameters[0x11].Value = data.AttachmentFlag;
            commandParameters[0x12] = new SqlParameter("@Feedback", SqlDbType.Int);
            commandParameters[0x12].Value = data.Feedback;
            commandParameters[0x13] = new SqlParameter("@SignLook", SqlDbType.Int);
            commandParameters[0x13].Value = data.SignLook;
            commandParameters[20] = new SqlParameter("@TurnPriv", SqlDbType.Int);
            commandParameters[20].Value = data.TurnPriv;
            commandParameters[0x15] = new SqlParameter("@MailTo", SqlDbType.NText);
            if (data.MailToIsNull)
            {
                commandParameters[0x15].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x15].Value = data.MailTo;
            }
            commandParameters[0x16] = new SqlParameter("@UserFilter", SqlDbType.Int);
            commandParameters[0x16].Value = data.UserFilter;
            commandParameters[0x17] = new SqlParameter("@AutoType", SqlDbType.Int);
            commandParameters[0x17].Value = data.AutoType;
            commandParameters[0x18] = new SqlParameter("@UserLock", SqlDbType.Int);
            commandParameters[0x18].Value = data.UserLock;
            commandParameters[0x19] = new SqlParameter("@TopDefault", SqlDbType.Bit);
            commandParameters[0x19].Value = data.TopDefault;
            commandParameters[0x1a] = new SqlParameter("@AutoUserOp", SqlDbType.NVarChar, 20);
            if (data.AutoUserOpIsNull)
            {
                commandParameters[0x1a].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x1a].Value = data.AutoUserOp;
            }
            commandParameters[0x1b] = new SqlParameter("@AutoUser", SqlDbType.NText);
            if (data.AutoUserIsNull)
            {
                commandParameters[0x1b].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x1b].Value = data.AutoUser;
            }
            commandParameters[0x1c] = new SqlParameter("@TimeOut", SqlDbType.Int);
            if (data.TimeOutIsNull)
            {
                commandParameters[0x1c].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x1c].Value = data.TimeOut;
            }
            object obj2 = SqlHelper.ExecuteScalar(conn, CommandType.Text, commandText, commandParameters);
            if (obj2 != null)
            {
                return Convert.ToInt32(obj2);
            }
            return -1;
        }

        public DataTable SelectByFlowId(SqlConnection conn, int flowId)
        {
            string commandText = "SELECT * FROM [dbo].[Flow_Process] WHERE [FlowId] = @FlowId";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@FlowId", SqlDbType.Int) };
            commandParameters[0].Value = flowId;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Flow_Process";
            return set.Tables[0];
        }

        public DataTable SelectById(SqlConnection conn, int id)
        {
            string commandText = "SELECT *, dbo.GetUserNames(CAST([PrcsUser] AS nvarchar(4000))) AS ToUserNames, dbo.GetDeptNames(CAST([PrcsDept] AS nvarchar(2000))) AS ToDeptNames, dbo.GetPrivNames(CAST([PrcsPriv] AS nvarchar(2000))) AS ToPrivNames, dbo.GetUserNames(CAST([MailTo] AS nvarchar(4000))) AS MailToNames, dbo.GetUserNames(CAST([AutoUserOp] AS nvarchar(4000))) AS AutoUserOpNames, dbo.GetUserNames(CAST([AutoUser] AS nvarchar(4000))) AS AutoUserNames FROM [dbo].[Flow_Process] WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int) };
            commandParameters[0].Value = id;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Flow_Process";
            return set.Tables[0];
        }

        public DataTable SelectByRunId(SqlConnection conn, int runId)
        {
            string commandText = "SELECT [Flow_Process].* FROM [dbo].[Flow_Process], [dbo].[Flow_Run] WHERE [Flow_Run].[RunId] = @RunId AND [Flow_Run].[FlowId] = [Flow_Process].[FlowId] ORDER BY [Flow_Process].[PrcsId] ASC ";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@RunId", SqlDbType.Int) };
            commandParameters[0].Value = runId;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Flow_Process";
            return set.Tables[0];
        }

        public DataTable SelectInfo(SqlConnection conn, int runId, int prcsId)
        {
            string commandText = "SELECT [Flow_Process].* FROM [dbo].[Flow_Process], [dbo].[Flow_Run] WHERE [Flow_Process].[FlowId] = [Flow_Run].[FlowId] AND [Flow_Process].[PrcsId] = @PrcsId AND [Flow_Run].[RunId] = @RunId";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@RunId", SqlDbType.Int);
            commandParameters[0].Value = runId;
            commandParameters[1] = new SqlParameter("@PrcsId", SqlDbType.Int);
            commandParameters[1].Value = prcsId;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Flow_Process";
            return set.Tables[0];
        }

        public void SetAutoItem(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [AutoItem] = @AutoItem WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@AutoItem", SqlDbType.NText);
            if (data.AutoItemIsNull)
            {
                commandParameters[1].Value = DBNull.Value;
            }
            else
            {
                commandParameters[1].Value = data.AutoItem;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public void SetBase(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [PrcsId] = @PrcsId, [PrcsName] = @PrcsName, [PrcsTo] = @PrcsTo, [Plugin] = @Plugin, [AttachmentFlag] = @AttachmentFlag, [Feedback] = @Feedback, [SignLook] = @SignLook, [TurnPriv] = @TurnPriv, [MailTo] = @MailTo, [UserFilter] = @UserFilter, [AutoType] = @AutoType, [UserLock] = @UserLock, [TopDefault] = @TopDefault, [AutoUserOp] = @AutoUserOp, [AutoUser] = @AutoUser, [TimeOut] = @TimeOut WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[0x11];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@PrcsId", SqlDbType.Int);
            commandParameters[1].Value = data.PrcsId;
            commandParameters[2] = new SqlParameter("@PrcsName", SqlDbType.NVarChar, 200);
            commandParameters[2].Value = data.PrcsName;
            commandParameters[3] = new SqlParameter("@PrcsTo", SqlDbType.NText);
            if (data.PrcsToIsNull)
            {
                commandParameters[3].Value = DBNull.Value;
            }
            else
            {
                commandParameters[3].Value = data.PrcsTo;
            }
            commandParameters[4] = new SqlParameter("@Plugin", SqlDbType.NText);
            if (data.PluginIsNull)
            {
                commandParameters[4].Value = DBNull.Value;
            }
            else
            {
                commandParameters[4].Value = data.Plugin;
            }
            commandParameters[5] = new SqlParameter("@AttachmentFlag", SqlDbType.Int);
            commandParameters[5].Value = data.AttachmentFlag;
            commandParameters[6] = new SqlParameter("@Feedback", SqlDbType.Int);
            commandParameters[6].Value = data.Feedback;
            commandParameters[7] = new SqlParameter("@SignLook", SqlDbType.Int);
            commandParameters[7].Value = data.SignLook;
            commandParameters[8] = new SqlParameter("@TurnPriv", SqlDbType.Int);
            commandParameters[8].Value = data.TurnPriv;
            commandParameters[9] = new SqlParameter("@MailTo", SqlDbType.NText);
            if (data.MailToIsNull)
            {
                commandParameters[9].Value = DBNull.Value;
            }
            else
            {
                commandParameters[9].Value = data.MailTo;
            }
            commandParameters[10] = new SqlParameter("@UserFilter", SqlDbType.Int);
            commandParameters[10].Value = data.UserFilter;
            commandParameters[11] = new SqlParameter("@AutoType", SqlDbType.Int);
            commandParameters[11].Value = data.AutoType;
            commandParameters[12] = new SqlParameter("@UserLock", SqlDbType.Int);
            commandParameters[12].Value = data.UserLock;
            commandParameters[13] = new SqlParameter("@TopDefault", SqlDbType.Bit);
            commandParameters[13].Value = data.TopDefault;
            commandParameters[14] = new SqlParameter("@AutoUserOp", SqlDbType.NVarChar, 20);
            if (data.AutoUserOpIsNull)
            {
                commandParameters[14].Value = DBNull.Value;
            }
            else
            {
                commandParameters[14].Value = data.AutoUserOp;
            }
            commandParameters[15] = new SqlParameter("@AutoUser", SqlDbType.NText);
            if (data.AutoUserIsNull)
            {
                commandParameters[15].Value = DBNull.Value;
            }
            else
            {
                commandParameters[15].Value = data.AutoUser;
            }
            commandParameters[0x10] = new SqlParameter("@TimeOut", SqlDbType.Int);
            if (data.TimeOutIsNull)
            {
                commandParameters[0x10].Value = DBNull.Value;
            }
            else
            {
                commandParameters[0x10].Value = data.TimeOut;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public void SetCondition(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [PrcsIn] = @PrcsIn, [PrcsOut] = @PrcsOut, [PrcsInSet] = @PrcsInSet, [PrcsOutSet] = @PrcsOutSet WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[5];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@PrcsIn", SqlDbType.NText);
            if (data.PrcsInIsNull)
            {
                commandParameters[1].Value = DBNull.Value;
            }
            else
            {
                commandParameters[1].Value = data.PrcsIn;
            }
            commandParameters[2] = new SqlParameter("@PrcsOut", SqlDbType.NText);
            if (data.PrcsOutIsNull)
            {
                commandParameters[2].Value = DBNull.Value;
            }
            else
            {
                commandParameters[2].Value = data.PrcsOut;
            }
            commandParameters[3] = new SqlParameter("@PrcsInSet", SqlDbType.NText);
            if (data.PrcsInSetIsNull)
            {
                commandParameters[3].Value = DBNull.Value;
            }
            else
            {
                commandParameters[3].Value = data.PrcsInSet;
            }
            commandParameters[4] = new SqlParameter("@PrcsOutSet", SqlDbType.NText);
            if (data.PrcsOutSetIsNull)
            {
                commandParameters[4].Value = DBNull.Value;
            }
            else
            {
                commandParameters[4].Value = data.PrcsOutSet;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public void SetHiddenItem(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [HiddenItem] = @HiddenItem WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@HiddenItem", SqlDbType.NText);
            if (data.HiddenItemIsNull)
            {
                commandParameters[1].Value = DBNull.Value;
            }
            else
            {
                commandParameters[1].Value = data.HiddenItem;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public void SetPrcsItem(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [PrcsItem] = @PrcsItem WHERE [Id] = @Id ";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@PrcsItem", SqlDbType.NText);
            if (data.PrcsItemIsNull)
            {
                commandParameters[1].Value = DBNull.Value;
            }
            else
            {
                commandParameters[1].Value = data.PrcsItem;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }

        public void SetPrcsUser(SqlConnection conn, FlowProcessData data)
        {
            string commandText = "UPDATE [dbo].[Flow_Process] SET [PrcsDept] = @PrcsDept, [PrcsPriv] = @PrcsPriv, [PrcsUser] = @PrcsUser WHERE [Id] = @Id";
            SqlParameter[] commandParameters = new SqlParameter[4];
            commandParameters[0] = new SqlParameter("@Id", SqlDbType.Int);
            commandParameters[0].Value = data.Id;
            commandParameters[1] = new SqlParameter("@PrcsDept", SqlDbType.NText);
            if (data.PrcsDeptIsNull)
            {
                commandParameters[1].Value = DBNull.Value;
            }
            else
            {
                commandParameters[1].Value = data.PrcsDept;
            }
            commandParameters[2] = new SqlParameter("@PrcsPriv", SqlDbType.NText);
            if (data.PrcsPrivIsNull)
            {
                commandParameters[2].Value = DBNull.Value;
            }
            else
            {
                commandParameters[2].Value = data.PrcsPriv;
            }
            commandParameters[3] = new SqlParameter("@PrcsUser", SqlDbType.NText);
            if (data.PrcsUserIsNull)
            {
                commandParameters[3].Value = DBNull.Value;
            }
            else
            {
                commandParameters[3].Value = data.PrcsUser;
            }
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
        }
    }
}

